package com.quickask.entity;

import org.hibernate.annotations.*;
import org.hibernate.annotations.Cache;

import javax.persistence.*;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
import java.sql.Timestamp;

/**
 * Created by NaSa on 2015/9/23.
 */
@Entity
@Table(name = "asknow_user", schema = "", catalog = "quickask")
@org.hibernate.annotations.Cache(usage= CacheConcurrencyStrategy.READ_WRITE, region = "com.quickask.entity.AsknowUserEntity")
public class AsknowUserEntity implements Serializable {
    private int userId; //用户id
    private String userAccount;  //用户普通账号
    private String userPassword;  //账户密码
    private String userToken;  //用户唯一token,每个用户唯一
    private String userPhone;  //用户手机号
    private String userPhoneZoneCode;  //手机区号
    private String userQq;  //用户QQ
    private String userWechat;  //用户微信
    private Timestamp userCreateDate;  //用户创建日期

    private AsknowUserPrivilegeEntity asknowUserPrivilegeEntity;
    private AsknowUserLocationEntity asknowUserLocationEntity;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "userId", nullable = false, insertable = true, updatable = true)
    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    @Column(name = "userAccount", nullable = true, unique = true, insertable = true, updatable = true, length = 50)
    public String getUserAccount() {
        return userAccount;
    }

    public void setUserAccount(String userAccount) {
        this.userAccount = userAccount;
    }

    @Column(name = "userPassword", nullable = true, insertable = true, updatable = true, length = 64)
    public String getUserPassword() {
        return userPassword;
    }

    public void setUserPassword(String userPassword) {
        this.userPassword = userPassword;
    }

    @Column(name = "userToken", nullable = true, insertable = true, updatable = true)
    public String getUserToken() {
        return userToken;
    }

    public void setUserToken(String userToken) {
        this.userToken = userToken;
    }

    @Column(name = "userPhone", nullable = true, unique = true, insertable = true, updatable = true, length = 20)
    public String getUserPhone() {
        return userPhone;
    }

    public void setUserPhone(String userPhone) {
        this.userPhone = userPhone;
    }

    @Column(name = "userQQ", nullable = true, unique = true, insertable = true, updatable = true, length = 64)
    public String getUserQq() {
        return userQq;
    }

    public void setUserQq(String userQq) {
        this.userQq = userQq;
    }

    @Column(name = "userWechat", nullable = true, unique = true, insertable = true, updatable = true, length = 64)
    public String getUserWechat() {
        return userWechat;
    }

    public void setUserWechat(String userWechat) {
        this.userWechat = userWechat;
    }

    @Column(name = "userCreateDate", nullable = true, insertable = true, updatable = true)
    public Timestamp getUserCreateDate() {
        return userCreateDate;
    }

    public void setUserCreateDate(Timestamp userCreateDate) {
        this.userCreateDate = userCreateDate;
    }

    @Column(name = "userPhoneZoneCode", nullable = true, insertable = true, updatable = true, length = 10)
    public String getUserPhoneZoneCode() {
        return userPhoneZoneCode;
    }

    public void setUserPhoneZoneCode(String userPhoneZoneCode) {
        this.userPhoneZoneCode = userPhoneZoneCode;
    }

    @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
    @JoinColumn(name = "userId")
    public AsknowUserPrivilegeEntity getAsknowUserPrivilegeEntity() {
        return asknowUserPrivilegeEntity;
    }

    public void setAsknowUserPrivilegeEntity(AsknowUserPrivilegeEntity asknowUserPrivilegeEntity) {
        this.asknowUserPrivilegeEntity = asknowUserPrivilegeEntity;
    }

    @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
    @JoinColumn(name = "userId")
    public AsknowUserLocationEntity getAsknowUserLocationEntity() {
        return asknowUserLocationEntity;
    }

    public void setAsknowUserLocationEntity(AsknowUserLocationEntity asknowUserLocationEntity) {
        this.asknowUserLocationEntity = asknowUserLocationEntity;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof AsknowUserEntity)) return false;

        AsknowUserEntity that = (AsknowUserEntity) o;

        if (userId != that.userId) return false;
        if (userAccount != null ? !userAccount.equals(that.userAccount) : that.userAccount != null) return false;
        if (userPassword != null ? !userPassword.equals(that.userPassword) : that.userPassword != null) return false;
        if (userToken != null ? !userToken.equals(that.userToken) : that.userToken != null) return false;
        if (userPhone != null ? !userPhone.equals(that.userPhone) : that.userPhone != null) return false;
        if (userPhoneZoneCode != null ? !userPhoneZoneCode.equals(that.userPhoneZoneCode) : that.userPhoneZoneCode != null)
            return false;
        if (userQq != null ? !userQq.equals(that.userQq) : that.userQq != null) return false;
        if (userWechat != null ? !userWechat.equals(that.userWechat) : that.userWechat != null) return false;
        if (userCreateDate != null ? !userCreateDate.equals(that.userCreateDate) : that.userCreateDate != null)
            return false;
        if (asknowUserPrivilegeEntity != null ? !asknowUserPrivilegeEntity.equals(that.asknowUserPrivilegeEntity) : that.asknowUserPrivilegeEntity != null)
            return false;
        return !(asknowUserLocationEntity != null ? !asknowUserLocationEntity.equals(that.asknowUserLocationEntity) : that.asknowUserLocationEntity != null);

    }

    @Override
    public int hashCode() {
        int result = userId;
        result = 31 * result + (userAccount != null ? userAccount.hashCode() : 0);
        result = 31 * result + (userPassword != null ? userPassword.hashCode() : 0);
        result = 31 * result + (userToken != null ? userToken.hashCode() : 0);
        result = 31 * result + (userPhone != null ? userPhone.hashCode() : 0);
        result = 31 * result + (userPhoneZoneCode != null ? userPhoneZoneCode.hashCode() : 0);
        result = 31 * result + (userQq != null ? userQq.hashCode() : 0);
        result = 31 * result + (userWechat != null ? userWechat.hashCode() : 0);
        result = 31 * result + (userCreateDate != null ? userCreateDate.hashCode() : 0);
        result = 31 * result + (asknowUserPrivilegeEntity != null ? asknowUserPrivilegeEntity.hashCode() : 0);
        result = 31 * result + (asknowUserLocationEntity != null ? asknowUserLocationEntity.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "AsknowUserEntity{" +
                "userId=" + userId +
                ", userAccount='" + userAccount + '\'' +
                ", userPassword='" + userPassword + '\'' +
                ", userToken='" + userToken + '\'' +
                ", userPhone='" + userPhone + '\'' +
                ", userPhoneZoneCode='" + userPhoneZoneCode + '\'' +
                ", userQq='" + userQq + '\'' +
                ", userWechat='" + userWechat + '\'' +
                ", userCreateDate=" + userCreateDate +
                ", asknowUserPrivilegeEntity=" + asknowUserPrivilegeEntity +
                ", asknowUserLocationEntity=" + asknowUserLocationEntity +
                '}';
    }
}
